#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void* thread_start(void* arg)
{
    (void)arg;
    printf("i am new thread\n");
    sleep(5);
    //printf("pthread_exit\n");
    //谁调用，谁退出
    pthread_exit(NULL);
    printf("%p\n", pthread_self());
    //pthread_cancel(pthread_self());
    while(1)
    {
        sleep(1);
        printf("111111~~~\n");
    }
    return NULL;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid, NULL, thread_start, NULL);
    
    sleep(5);
    // 整个程序是否退出？ 退出0 不退出1
    //pthread_exit(NULL);
    //pthread_cancel(tid);
    pthread_join(tid, NULL);
    while(1)
    {
        printf("i am main thread\n");
        sleep(1);
    }
    return 0;
}
